<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.ostrich.system.bean.TostSysParaminfo"%>
<%@page import="com.ostrich.system.analysis.ParaminfoUtil"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   <%@include file="/view/resource.jsp" %>
  </head>
 <script type="text/javascript">
$("#searchid").ready(function (){
	$.ajax({
		url:urls['msUrl']+"tostPjProjcttab/getProject.do",
		dataType:'json',
		success:function(result){
			var str="<select name='id' id='id'><option></option>";
			for(var i=0;i<result.total;i++){
				str+="<option value='"+result.rows[i].id+"'>"+result.rows[i].pjProjectname+"("+getstname(result.rows[i].pjStatus)+")"+"</option>";
			}
			str+="</select>";
			document.getElementById("searchid").innerHTML=str;
		}
	});
});
$(document).ready(function() { 
$("#pjCode").blur(function(){
var LpjCode = $("#pjCode").val();
if(null == LpjCode || undefined == LpjCode || "" == LpjCode){
document.getElementById("xspjcode").innerHTML="请输入编号";
}else {
document.getElementById("xspjcode").innerHTML="";
$.ajax({
      type:"post",
      url:urls['msUrl']+"/tostPjProjcttab/checkPjcode.do",
      dataType:"text",
      data:{pjCode:LpjCode},
      success: function(result){
          if(result == 1){
          document.getElementById("xspjcode").innerHTML=LpjCode+"可以使用";
          }
          if(result == -1){
          document.getElementById("xspjcode").innerHTML=LpjCode+"已经被使用,请使用其他编号";
          }
      }
});
}
});
});


function getstname (pjStatus){
	var pjstname = "启动.";
	if(pjStatus!=null && pjStatus!=''){
		if(pjStatus=='0')
			pjstname = "启动";
		else if(pjStatus=='1')
			pjstname = "执行";
		else if(pjStatus=='2')
			pjstname = "暂停";
		else if(pjStatus=='3')
			pjstname = "完成";
	}
	return pjstname;
}
$(document).ready(function (){
	$("#btn-search-pro").click(function(){
		var slid = document.getElementById("id").value;
		$.ajax({
		url:urls['msUrl']+"tostPjProjcttab/getId.do?id="+slid,
		dataType:'json',
		type:'post',
		success:function(result){
			var rdata = result.data;
			if(rdata!=null){
			    document.editForm.sub1.value="编辑保存";
				document.getElementById("pjProjectname").value=rdata.pjProjectname;
				document.editForm.pjCode.value=rdata.pjCode;
				document.editForm.pjProjectname.value=rdata.pjProjectname;
				document.editForm.pjPartyaname.value=rdata.pjPartyaname;
				document.editForm.id.value=rdata.id;
				document.editForm.pjDesc.value=rdata.pjDesc;
				
				
				 var pjWorkjoin=(rdata.pjWorkjoin==undefined)?"":rdata.pjWorkjoin;
				 document.getElementById("xpjWorkjoin").innerHTML=pjWorkjoin;
				
				document.getElementById("xpjContract").innerHTML=rdata.pjContract;
				//document.editForm.pjContract.value=rdata.pjContract;
				var pjContracttime=(rdata.pjContracttime==undefined)?"":rdata.pjContracttime;
				document.getElementById("xpjContracttime").innerHTML=pjContracttime;
				//document.editForm.pjContracttime.value=rdata.pjContracttime;
				var pjWeal=(rdata.pjWeal==undefined)?"":rdata.pjWeal;
				document.getElementById("xpjWeal").innerHTML=pjWeal;
				//document.editForm.pjWeal.value=rdata.pjWeal;
				var pjAssign=(rdata.pjAssign==undefined)?"":rdata.pjAssign;
				document.getElementById("xpjAssign").innerHTML=pjAssign;
				//document.editForm.pjAssign.value=rdata.pjAssign; 
				document.editForm.pjUrge.value=rdata.pjUrge; 
				var pjPercent=(rdata.pjPercent==undefined)?"":rdata.pjPercent;
				document.getElementById("xpjPercent").innerHTML=pjPercent;
				//document.editForm.pjPercent.value=rdata.pjPercent;
				document.getElementById("selpjStatus").value=rdata.pjStatus;
				document.getElementById("pjStatus").value=rdata.pjStatus;
				document.getElementById("xpjStatus").innerHTML=getstname(rdata.pjStatus);
				document.getElementById("xspjcode").innerHTML="";
				document.getElementById("xspjProjectnam").innerHTML="";
				document.getElementById("xspjPartyaname").innerHTML="";
			}
		}
		});
	});
});


function getPjcontract(){
	var obj = document.getElementById("selpjContract");
	var index = obj.selectedIndex; // 选中索引
	var	text = obj.options[index].text;
	var	value =  obj.options[index].value;
	document.editForm.pjContract.value=value;
	document.getElementById("xpjContract").innerHTML=text;
}

function getpjStatus(){
	var obj = document.getElementById("selpjStatus");
	var index = obj.selectedIndex;
	var	text = obj.options[index].text;
	var	value =  obj.options[index].value;
	document.getElementById("pjStatus").value=value;
	document.getElementById("xpjStatus").innerHTML=text;
}

function setreset(){
document.editForm.reset();
document.getElementById("pjProjectname").innerHTML="";
document.getElementById("xpjWorkjoin").innerHTML="";
document.getElementById("xpjContract").innerHTML="";
document.getElementById("xpjContracttime").innerHTML="";
document.getElementById("xpjWeal").innerHTML="";
document.getElementById("xpjAssign").innerHTML="";
document.getElementById("xpjPercent").innerHTML="";
document.getElementById("xspjcode").innerHTML="";
document.getElementById("xspjProjectnam").innerHTML="";
document.getElementById("xspjPartyaname").innerHTML="";
document.editForm.sub1.value="新建项目";
}
function delet(){
var lpjCode = document.getElementById("pjCode").value;
var lpjName = document.getElementById("jpjProjectname").value;
if(null == lpjCode || undefined == lpjCode || "" == lpjCode ){
alert("删除失败：请先选择项目，点击查询，在进行该操作");
}else {
	if(confirm("您确认删除"+lpjName+"项目信息吗？")){
	document.editForm.action="delete.do";
	alert("操作成功");
	document.editForm.submit();
	}
	}
}
function addupdate(){
var spjcode = document.getElementById("pjCode").value;
var spjProjectnam = document.getElementById("jpjProjectname").value;
var spjPartyaname = document.getElementById("jpjPartyaname").value;
var obj = document.getElementById("selpjContract");
var index = obj.selectedIndex; // 选中索引
var	text = obj.options[index].text;
var	value =  obj.options[index].value;
var contracttime = $("#pjContracttime").datebox('getValue');
if(null == spjcode || undefined == spjcode || "" == spjcode){
document.getElementById("xspjcode").innerHTML="请输入编号";
}else  document.getElementById("xspjcode").innerHTML="";
if(null == spjProjectnam || undefined == spjProjectnam ||"" == spjProjectnam){
document.getElementById("xspjProjectnam").innerHTML="请输入项目名称";
}else document.getElementById("xspjProjectnam").innerHTML="";
if(null == spjPartyaname || undefined == spjPartyaname ||"" == spjPartyaname){
document.getElementById("xspjPartyaname").innerHTML="请输入甲方名称";
}else document.getElementById("xspjPartyaname").innerHTML="";
if((value=="已经签订") && (null==contracttime ||undefined ==contracttime || ""== contracttime)){
document.getElementById("xpjContracttime").innerHTML="请选择合同签订时间";
}
else {
//获取到时间控件的值赋值给hidden。
document.getElementById("xspjPartyaname").innerHTML="";
document.getElementById("workjoin").value=$("#pjWorkjoin").datebox('getValue');
document.getElementById("contracttime").value=$("#pjContracttime").datebox('getValue');
document.getElementById("weal").value=$("#pjWeal").datebox('getValue');
document.getElementById("assign").value=$("#pjAssign").datebox('getValue');
document.getElementById("percent").value=$("#pjPercent").datebox('getValue');
alert("操作成功！");
document.editForm.submit();
}
}

 </script>   
  <body>
  <br/>
  	 <!-- Search panel start -->
 	 <form id="searchForm">
 	 	<input class="hidden" id='search_parentId' name="parentId">
 	 	<p class="ui-fields">
            <label class="ui-label">请选择项目:</label> 
            <span id="searchid"></span>
        </p>
        <a id="btn-search-pro" class="easyui-linkbutton" iconCls="icon-search">查询</a>
      </form>  
     <div>
      <table title="项目信息" style="width:500px;height:450px;">  
     	<form id="editForm" name="editForm" action="save.do" method="post"> 
     	 <!-- 隐藏文本框 -->
     	 <input class="hidden" name="id">
     	 <input class="hidden" name="deleted">
    	 <input class="hidden" name="parentId" id='edit_parentId'>
    	 <tr><td>
	               <div class="ftitle"><span id="pjProjectname">详细</span></div>    
		           <div class="fitem">  
		               <label>编号:</label>  
		               <input class="easyui-validatebox" type="text" name="pjCode" id="pjCode">
		           		<span id="xspjcode"></span>
		           </div>  
		           <div class="fitem">  
		               <label>项目名称:</label>  
		               <input class="easyui-validatebox" type="text" name="pjProjectname" id="jpjProjectname">
		           		<span id="xspjProjectnam"></span>
		           </div>  
		           <div class="fitem">  
		               <label>甲方名称:</label>  
		               <input class="easyui-validatebox" type="text" name="pjPartyaname"  id="jpjPartyaname">
		           		<span id="xspjPartyaname"></span>
		           </div>  
		           <div class="fitem">  
		               <label>项目类型:</label>  
		               <select name="pjType" id="pjType"><% Map<Integer,TostSysParaminfo> type = ParaminfoUtil.getParamByPid(80); 
		               for(Map.Entry<Integer,TostSysParaminfo> m:type.entrySet()){
		               	%><option value="<%=m.getValue().getId()%>"><%=m.getValue().getPaName() %></option><%} %>
		              </select>
		           </div>  
		           <div class="fitem">  
		               <label>项目备注:</label>  
		               <input class="easyui-validatebox" type="text" name="pjDesc" >
		           </div>  
		           <div class="fitem">  

		               <label>工作衔接函:</label>
		               <input type="hidden" name="pjWorkjoin" id="workjoin">
		               <input class="easyui-datebox" editable="false" type="text" id="pjWorkjoin">
		               <span id="xpjWorkjoin"></span>

		           </div>
		           <div class="fitem">
		               <label>合同签订:</label>  
		               <input type="hidden" name="pjContract" id="pjContract">
		               <select id="selpjContract"  onchange="getPjcontract()">
		               <option value="已经签订">已经签订</option>
		               <option value="没有签订">没有签订</option>
		               </select>
		               <span id="xpjContract"></span>
		           </div>  
		           <div class="fitem">  
		               <label>合同签订时间:</label>

		               <input type="hidden" name="pjContracttime" id="contracttime">
		               <input class="easyui-datebox" id="pjContracttime" editable="false" type="text" data-options="required:true" >

		                  <span id="xpjContracttime"></span>
		           </div> 
		           <div class="fitem">  
		               <label>过渡期薪酬福利:</label>
		               <input type="hidden" name="pjWeal" id="weal">
		               <input class="easyui-datebox" editable="false" type="text" id="pjWeal" >
		                 <span id="xpjWeal"></span>
		           </div>  
		           <div class="fitem">  
		               <label>提成分配:</label>
		               <input type="hidden" name="pjAssign" id="assign">
		               <input class="easyui-datebox" editable="false" type="text" id="pjAssign" >
		                  <span id="xpjAssign"></span>
		           </div>  
		           <div class="fitem">  
		               <label>催款说明:</label>  
		               <input class="easyui-validatebox" type="text" name="pjUrge">
		           </div>  
		           <div class="fitem">  
		               <label>提成发放:</label>
		               <input type="hidden" name="pjPercent" id="percent">
		               <input class="easyui-datebox" editable="false" type="text" id="pjPercent" >
		                 <span id="xpjPercent"></span>
		           </div> 
		            <div class="fitem">  
		               <label>状态:</label>
		               <input type="hidden" name="pjStatus" id="pjStatus">
		               <select id="selpjStatus" onchange="getpjStatus()">
		               <option value="0">启动</option>
		               <option value="1">执行</option>
		               <option value="2">暂停</option>
		               <option value="3">完成</option>
		               </select>
		                 <span id="xpjStatus"></span>
		           </div>
		           <div>
		           <input type="button"  onclick="addupdate()" name="sub1" value="新建项目">
		           <input type="button" onclick="setreset()" value="重置">
		           <input type="button" onclick="delet()" value="删除项目">
		           </div>
	            </div>
	            </td></tr>
     	</form>
  	 </table>
     </div>
    
  </body>
</html>